package com.personal.service.impl;

import com.personal.dao.OccupancyApplyDao;
import com.personal.domain.OccupancyApply;
import com.personal.service.OccupancyApplyService;
import com.personal.util.partDisplay.OccupancyApplyPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.service.impl
 * @className: OccupancyApplyServiceImpl
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/9 11:07
 * @version: 1.0
 */


@Service
public class OccupancyApplyServiceImpl implements OccupancyApplyService {


    @Autowired
    private OccupancyApplyDao occupancyApplyDao;

    @Override
    public List<OccupancyApply> selectAll() {

        return occupancyApplyDao.selectAll();

    }

    @Override
    public List<OccupancyApplyPart> selectPartAll() {
        return occupancyApplyDao.selectPartAll();
    }

    @Override
    public List<OccupancyApplyPart> selectPartByKey(String name, String type) {
        return occupancyApplyDao.selectPartByKey(name,type);
    }

    @Override
    public boolean add(OccupancyApply occupancyApply) {
        int flag=occupancyApplyDao.add(occupancyApply);
        if(flag>0)
            return true;
        return false;
    }

    @Override
    public OccupancyApply getUpdateData(int id){
        return occupancyApplyDao.getUpdateData(id);
    }
    @Override
    public boolean update(OccupancyApply occupancyApply) {
        int flag = occupancyApplyDao.update(occupancyApply);
        if (flag > 0) {
            return true;
        }
        return false;
    }

    // 存疑：
    /*删除操作，预期结果：
    * 针对多次持久层操作，开启了spring事务管理
    * 当多次持久层操作出现错误时，将回滚此前所有操作
    * 并且由异常管理器捕获异常，结束此次请求操作*/
    // 拓展：是否所有的持久层操作失败，均会以持久层抛错？
    @Override
    public boolean delete(List<Integer> ids) {

        for(int id:ids){
            int flag=occupancyApplyDao.delete(id);
            if(flag<0){
                return false;
            }
        }
        return true;
    }
}
